package com.yuyang.wifi.views;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.yuyang.wifi.R;


/**
 * Created by Administrator on 2017/5/22.
 * ActivityTopBar
 */

public class NormalWhiteTopBar extends RelativeLayout {

    private ImageView mleftIcon, mCentreIcon, mRightIcon;
    private TextView mLeftText, mCentretitle, mRightText;
    private View bottomLine;
    private final RelativeLayout barBgColor;

    public NormalWhiteTopBar(Context context, AttributeSet attrs) {
        super(context, attrs);
        View.inflate(context, R.layout.normal_white_layout_title, this);
        // TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.normalWhiteTopBar);
        //titleStr = typedArray.getString(R.styleable.normalWhiteTopBar_whiteTitleStr);
        //rightStr = typedArray.getResourceId(R.styleable.normalWhiteTopBar_whiteRightImage, 0);
        //leftInt = typedArray.getResourceId(R.styleable.normalWhiteTopBar_whiteLeftImage, 0);

        mleftIcon = findViewById(R.id.left_icon);//左边图片
        mLeftText = findViewById(R.id.left_text);//左边文本

        mCentreIcon = findViewById(R.id.centre_icon);//中间图片
        mCentretitle = findViewById(R.id.centre_title);//中间标题

        mRightIcon = findViewById(R.id.right_icon);//右边图片
        mRightText = findViewById(R.id.right_text);//右边文本

        bottomLine = findViewById(R.id.bottom_line);//底部线

        barBgColor = findViewById(R.id.bar_bg_color);

//        Centretitle.setText(titleStr);
//        title_right_iv.setImageResource(rightStr);
//        left_iv.setImageResource(leftInt);
        //invalidate();
    }


    /**
     * @desc 设置actionbar title
     */
    public TextView setActionBarCentreTitle(String title) {
        mCentretitle.setText(title);
        mCentretitle.setVisibility(View.VISIBLE);
        return mCentretitle;
    }

    /**
     * @desc 设置actionbar 中心图标和点击事件
     */
    public ImageView setsetActionBarCentreIcon(int resId) {
        if (resId < 0) {
            mCentreIcon.setImageDrawable(new ColorDrawable(Color.TRANSPARENT));
            mCentreIcon.setVisibility(View.INVISIBLE);
        } else {
            mCentreIcon.setImageResource(resId);
            mCentreIcon.setVisibility(View.VISIBLE);
            mCentreIcon.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {


                }
            });
        }
        return mCentreIcon;
    }

    public void setActionBarBgColor(int color) {
        barBgColor.setBackgroundColor(color);
    }


    public TextView setActionBarLeftStr(String text) {
        mLeftText.setText(text);
        mLeftText.setVisibility(View.VISIBLE);
        return mLeftText;
    }

    public ImageView setsetActionBarLeftIcon(int resId) {
        if (resId < 0) {
            mleftIcon.setImageDrawable(new ColorDrawable(Color.TRANSPARENT));
            mleftIcon.setVisibility(View.INVISIBLE);
        } else {
            mleftIcon.setImageResource(resId);
            mleftIcon.setVisibility(View.VISIBLE);
        }
        return mleftIcon;
    }

    public TextView setActionBarRightStr(String text) {
        mRightText.setText(text);
        mRightText.setVisibility(View.VISIBLE);
        return mRightText;
    }

    public ImageView setsetActionBarRightIcon(int resId) {
        if (resId < 0) {
            mRightIcon.setImageDrawable(new ColorDrawable(Color.TRANSPARENT));
            mRightIcon.setVisibility(View.INVISIBLE);
        } else {
            mRightIcon.setImageResource(resId);
            mRightIcon.setVisibility(View.VISIBLE);
        }
        return mRightIcon;
    }

    public View setsetActionBarBottomLine(boolean isShow) {
        if (isShow) {
            bottomLine.setVisibility(View.VISIBLE);
        } else {
            bottomLine.setVisibility(View.INVISIBLE);
        }
        return bottomLine;
    }
}
